package com.hcb.tonguetiphealth.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.hcb.tonguetiphealth.model.Comment;
import com.hcb.tonguetiphealth.view.R;

public class CommentListAdapter extends BaseAdapter {

	private Context mContext;
	private List<Comment> mList;
	private LayoutInflater vi;
	
	public CommentListAdapter(Context context,List<Comment> list) {
		mContext = context;
		mList = list;
	}
	
	public int getCount() {
		if(mList == null) {
			return 0;
		}
		return mList.size();
	}
	
	public Object getItem(int position) {
		if(mList == null) {
			return null;
		} else {
			return mList.get(position);
		}
	}
	
	public long getItemId(int position) {
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {

		View view;
		
		if(convertView == null) {
			vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = (LinearLayout) vi.inflate(R.layout.comment_list_item, null);
		} else {
			view = convertView;
		}
		FillDataIntoView(view, position);
		
		return view;
	}
	
	private void FillDataIntoView(View view, final int position) {
		final Comment comment = mList.get(position);

		TextView tv_name = (TextView)view.findViewById(R.id.comment_name_textview);
		TextView tv_time = (TextView)view.findViewById(R.id.comment_time_textview);
		TextView tv_content = (TextView)view.findViewById(R.id.comment_content_textview);
		TextView tv_product = (TextView)view.findViewById(R.id.comment_product_textview);
		TextView tv_environment= (TextView)view.findViewById(R.id.comment_environment_textview);
		TextView tv_serve = (TextView)view.findViewById(R.id.comment_serve_textview);
		RatingBar rating = (RatingBar)view.findViewById(R.id.comment_rating_ratingbar);

		tv_name.setText(comment.getUser());
		tv_time.setText(comment.getTime());
		tv_content.setText(comment.getContent());
		tv_product.setText(comment.getProduct());
		tv_environment.setText(comment.getEnvironment());
		tv_serve.setText(comment.getServe());
		rating.setRating(comment.getRating());
	}

	@Override
	public boolean isEnabled(int position) {
		// TODO Auto-generated method stub
		//return super.isEnabled(position);
		return false;
	}
}
